<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:c="http://java.sun.com/jsp/jstl/core"

      xmlns:h="http://java.sun.com/jsf/html">

    <ui:composition template="/WEB-INF/layout/standard.xhtml">
        <ui:define name="title">simple login</ui:define>
        <ui:define name="content">

            <c:set var="path" value="${facesContext.externalContext.requestContextPath}" />
            <h3>A Simple Login</h3>

            <p>
                You are currently logged in as <h:outputText value="${idBean.user.name}" />.
            </p>
            <div style="display:none">
            <form id="loginForm" action="${path}/login/services/login/"
                  method="POST" accept-charset="UTF-8"
                  >
                    <input id="inputEmail" type="text" name="email" value="" />
                    <input id="inputSecret" type="text" name="secret" value="" />
                    <input type="hidden" name="loginOkURL" value="${requestScope['javax.servlet.forward.request_uri']}" />
                    <input type="hidden" name="loginFailedURL" value="${path}/login/view/en/loginFailed.jsf" />
            </form>
            </div>
            <p>
                Authenticate with the frickjack.com littleId service with Google or Yahoo openId credentials.
            </p>
                    <div id="littleIdUI" class="littleId_popup"></div>

            <script type="text/javascript" language="JavaScript">
      // <![CDATA[
      littleware.littleYUI.bootstrap().use( 'node', 'node-base', 'littleware-littleId', function(Y) {
              var login = Y.littleware.littleId.LoginProcess;
              var urlBase = /^(https?:\/\/[^\/]+\/\w+\/).+/.exec( window.location.href )[1];
              // open-id popup should redirect back to our popupReturn page with a GET HTTP request
              login.set( 'replyToURL', urlBase + "openId/view/en/demo/popupReturn.jsf" );
              login.set( 'replyMethod', 'GET' );
              // expose littleware.littleId for global access by the open-id popup
              littleware.littleId = Y.littleware.littleId
              login.promptUserForProvider()
              login.after( 'loginStateChange', function(ev) {
                  var state = login.get( 'loginState' )
                  Y.log( "Login state changed! : " + state )
                  if ( state == 'CredsReady' ) {
                      var creds = login.get( 'userCreds' );
                      Y.one( '#inputEmail' ).set( 'value', creds.email );
                      Y.one( '#inputSecret' ).set( 'value', creds.secret )
                      //alert( "bla!" )
                      Y.one( '#loginForm' ).submit()
                  }
              });
      }
      );
      // ]]>
            </script>

        </ui:define>
    </ui:composition>
</html>

